package cliCloud

import (
	"gitee.com/gitee-go/runner-core/comm"
	"gitee.com/gitee-go/utils"
	hbtp "github.com/mgr9525/HyperByte-Transfer-Protocol"
	"time"
)

const (
	RPCHostCode = 1
)

func genTokens(req *hbtp.Request) string {
	hd := req.ReqHeader()
	return utils.Md5String(hd.Path + hd.RelIp + hd.Times + comm.MainCfg.Secret)
}
func NewReq(method string, tmots ...time.Duration) (*hbtp.Request, error) {
	return hbtp.NewDoRPCReq(comm.MainCfg.ServAddr, RPCHostCode, method, comm.MainId, genTokens, tmots...)
}
func DoJson(method string, in, out interface{}, hd ...map[string]interface{}) error {
	req, err := NewReq(method)
	if err != nil {
		return err
	}
	return hbtp.DoJson(req, in, out, hd...)
}
func DoString(method string, in interface{}, hd ...hbtp.Mp) (int, []byte, error) {
	req, err := NewReq(method)
	if err != nil {
		return 0, nil, err
	}
	return hbtp.DoString(req, in, hd...)
}
